package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
    /**
     * 获取总记录数
     */
//    @Select("select count(*) from emp left join dept on emp.dept_id = dept.id")
//    Long count();

    /**
     * 分页查询
     */
//    @Select("select emp.*, dept.name deptName from emp left join dept on emp.dept_id = dept.id ")
//    List<Emp> list();


    /**
     * 员工查询
     */
//    @Select("select emp.*, dept.name deptName from emp left join dept on emp.dept_id = dept.id ")
//    List<Emp> list();
    public List<Emp> list(EmpQueryParam param);

    /**
     * 批量删除员工信息
     */
    void deleteByIds(List<Integer> ids);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);


    Emp getById(Integer id);

    void updateById(Emp emp);

    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp getUsernameAndPassword(Emp emp);


    @MapKey("pos")
    List<Map<String,Object>> countEmpJobData();

    @MapKey("name")
    List<Map> countEmpGenderData();

}